<?php
// +----------------------------------------------------------------------
// | Action ：首页
// +----------------------------------------------------------------------
// | DateTime：2015年12月8日
// +----------------------------------------------------------------------
// | Author: Danson <zoudan916@163.com>
// +----------------------------------------------------------------------

namespace Home\Controller;
use Admin\LordModel;
use Admin\PictureModel;
/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends WapController {

    public function action(){
        return 'Index/index';
    }

	/* 首页 */
    public function index(){
        $arr = M()->query('select SUM(voet_num) as voet_num,SUM(scan_num) as scan_num,COUNT(lord_id) as lord_count from hm_lord_user');
        $all[1] = M('dianzan')->where(array('guests'=>1))->count();
        $all[2] = M('dianzan')->where(array('guests'=>2))->count();
        $all[3] = M('dianzan')->where(array('guests'=>3))->count();
        $all[4] = M('dianzan')->where(array('guests'=>4))->count();
        $info = M('lord_user')->where(array('openid'=>$_SESSION['wx_user']['openid']))->find();
        $this->assign('all',$all);
        $this->assign('arr',$arr);
        $this->assign('info',$info);
        $this->display();
    }

    /* 发送短信 */
    public function ajaxCode(){
        $phone = I('post.phone');
        $code = rand(100000,999999);
        $result = send_sms($phone,'您的验证码是：'.$code.'，此验证码5分钟内有效。');
        if(empty($result)){
            $this->ajaxReturn(array('status'=>0,'msg'=>'发送失败,请确认你的手机号码'));
        }else{
            $this->ajaxReturn(array('status'=>1,'msg'=>$code));
        }
    }

    /* 嘉宾点赞 */
    public function ajaxDian(){
        $guests = I('post.guests');
        $all = M('dianzan')->where(array('guests'=>$guests,'openid'=>$_SESSION['wx_user']['openid']))->find();
        if(empty($all)){
            $id = M('dianzan')->add(array('guests'=>$guests,'openid'=>$_SESSION['wx_user']['openid'],'time'=>time()));
            $info['num'] = M('dianzan')->where(array('guests'=>$guests))->count();
            $info['status'] = 1;
            $info['voet'] = $id;
            $this->ajaxReturn($info);
        }else{
            $this->ajaxReturn(array('status'=>0));
        }
    }
}